package com.ruoyi.web.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.BdmGood;
import com.ruoyi.system.domain.dto.IntegralGoodDto;
import com.ruoyi.system.enums.BdmGoodEnum;
import com.ruoyi.system.service.IBdmGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 积分商品Controller
 * 
 * @author ruoyi
 * @date 2024-12-07
 */
@RestController
@RequestMapping("/admin/integralGood")
@Validated
public class BdmIntegralGoodController extends BaseController
{
    @Autowired
    private IBdmGoodService bdmGoodService;

    /**
     * 查询积分商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BdmGood bdmGood)
    {
        startPage();
        bdmGood.setPointsRedemption(BdmGoodEnum.DEDUCTION.getType().toString());
        List<BdmGood> list = bdmGoodService.selectbdmGoodList(bdmGood);
        return getDataTable(list);
    }


    /**
     * 获取积分商品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bdmGoodService.selectbdmGoodById(id));
    }


    /**
     * 新增积分商品
     */
    @PostMapping
    public AjaxResult integralGood(@Valid @RequestBody IntegralGoodDto integralGoodDto){
        return  toAjax(bdmGoodService.integralGood(integralGoodDto));
    }

    /**
     * 修改 积分 商品
     */
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralGoodDto integralGoodDto)
    {
        BdmGood bdmGood = BeanUtil.copyProperties(integralGoodDto, BdmGood.class);
        return toAjax(bdmGoodService.updatebdmGood(bdmGood));
    }

    /**
     * 删除 积分 商品
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bdmGoodService.lambdaUpdate().set(BdmGood::getPointsRedemption, BdmGoodEnum.NODEDUCTION.getType())
                .in(BdmGood::getId, Arrays.asList(ids)).update());
    }




}
